//spu管理模块接口
import request from "../../../utils/request.ts";
import type {
    T_AllTradeMarkResponse,
    T_SpuImageResponse,
    T_SpuResponseData,
    T_SaleAttrResponseData,
    T_SaleAllAttrResponse, T_SpuData, T_SkuData, T_SkuInfoResponseData
} from "./type.ts";


enum API {
    //获取已有的SPU数据
    GETSPU_URL = "/admin/product/",
    //获取全部品牌的数据
    ALLTRADEMARK_URL = "/admin/product/baseTrademark/getTrademarkList",
    //获取某一个SPU下的全部售卖商品的图片数据
    IMAGE_URL = "/admin/product/spuImageList/",
    //获取某一个SPU下全部的已有的销售属性接口地址
    SPUHASSALEATTR_URL = "/admin/product/spuSaleAttrList/",
    //获取整个项目全部的销售属性【颜色、版本、尺码】
    ALLSALEATTR_URL = "/admin/product/baseSaleAttrList",
    //追加新的spu
    ADDSPU_URL = "/admin/product/saveSpuInfo",
    //更新已有的spu
    UPDATESPU_URL = "/admin/product/updateSpuInfo",
    //追加一个新的Sku地址
    ADDSKU_URL = "/admin/product/saveSkuInfo",
    //查看某个已有SPU下的全部售卖的商品
    SKUINFO_URL = "/admin/product/findBySpuId/",
    //删除已有的Spu
    REMOVESPU_URL = "/admin/product/deleteSpu/"
}

//根据三级分类获取SPU数据
export const reqGetSpu = (page: number, limit: number, category3Id: string | number) => request.get<any, T_SpuResponseData>(API.GETSPU_URL + `${page}/${limit}?category3Id=${category3Id}`)

//获取全部spu品牌的数据
export const reqAllTradeMark = () => request.get<any, T_AllTradeMarkResponse>(API.ALLTRADEMARK_URL)

//获取某个已有的SPU下全部商品的图片地址
export const reqSpuImageList = (spuId: number) => request.get<any, T_SpuImageResponse>(API.IMAGE_URL + spuId)

//获取某一个已有的SPU拥有多少个销售属性
export const reqSpuHasSaleAttr = (spuId: number) => request.get<any, T_SaleAttrResponseData>(API.SPUHASSALEATTR_URL + spuId)

//获取全部的销售属性
export const reqGetAllSaleAttr = () => request.get<any, T_SaleAllAttrResponse>(API.ALLSALEATTR_URL)

//添加/更新SPU
export const reqAddOrUpdateSpu = (data: T_SpuData) => {
    //如果有id为更新，否则为新增
    if (data.id) {
        return request.post<any, any>(API.UPDATESPU_URL, data);
    } else {
        return request.post<any, any>(API.ADDSPU_URL, data);
    }
}

//添加sku请求的方法
export const reqAddSku = (data: T_SkuData) => request.post<any, any>(API.ADDSKU_URL, data)

//查看已有SPU下的全部售卖的商品
export const reqSkuList = (spuId: number | string) => request.get<any, T_SkuInfoResponseData>(API.SKUINFO_URL + spuId)

//删除已有的spu
export const reqRemoveSpu = (spuId: number | string) => request.delete<any, any>(API.REMOVESPU_URL + spuId)

